import { View } from "../../../mvc/core/View";
import { GTextFormat } from "../../../common/GTextFormat";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { ResFileConst } from "../../resource/ResFileConst";
import { Cache } from "../../cache/Cache";
import { Language } from "../../../../extend/language/Language";
import { ECamp } from "../../../../Message/Public/ECamp";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { ObjCreate } from "../common/ObjCreate";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../resource/ImagesConst";
import { TaskTargetInfo } from "../../model/TaskTargetInfo";
import { FlyFootBmp } from "../mapUI/flyFoot/FlyFootBmp";
import { AIManager } from "../../scene/ai/AIManager";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { AIType } from "../../scene/ai/AIType";
import { GButton } from "../../../../com/mui/controls/GButton";
type int = number;
//class RunBusinessNpcPanel
    
    export  class RunBusinessNpcPanel extends View
    {
        constructor()
        {
            super();
            this._npcInfoDic = new Map<any, any> /* flash.utils.Dictionary */();
            this._mapNameArr = [];
            this._flyFootArr = [];
            this._targetInfoArr = [];
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            var loc1=null;
            this._tfBlue = new GTextFormat("", 14, 41727);
            loc1 = new GTextFormat("", 12, 914795);
            this._traderImg = new Object /* flash.display.Bitmap */();
            this._traderImg.x = 195;
            this._traderImg.y = -5;
            addChild(this._traderImg);
            LoaderHelp.addResCallBack(ResFileConst.runBusiness, this.onResLoaded);
            this._selfCamp = Cache.instance.role.entityInfo.camp;
            var loc2=this.createTextfield(130, 93, 150, 20, Language.getString(35317), loc1);
            var loc3=[ECamp._ECampOne, ECamp._ECampTwo, ECamp._ECampThree];
            var loc4=loc3.indexOf(this._selfCamp);
            loc3.splice(loc4, 1);
            this.getRunBusinessNpc(ECamp._ECampNeutral, 50, 30, GlobalStyle.textFormat5);
            this.getRunBusinessNpc(this._selfCamp, 50, 60, GlobalStyle.textFormat5);
            this.getRunBusinessNpc(loc3[0], 280, 30, GlobalStyle.textFormat5);
            this.getRunBusinessNpc(loc3[1], 280, 60, GlobalStyle.textFormat5);
            this._introBtn = ObjCreate.createGButton(Language.getString(35318), 300, 90, 70, 25, this);
            this._introBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onIntroBtnClickHandler);
            return;
        }

        /* internal  */onResLoaded(): void
        {
            this._traderImg.bitmapData = GlobalClass.getBitmapData(ImagesConst.RbTraderPosTitle);
            return;
        }

        /* internal  */createTextfield(arg1: int, arg2: int, arg3: int, arg4: int, arg5: string, arg6: Object /* flash.text.TextFormat */): Object /* flash.text.TextField */
        {
            var loc1;
            (loc1 = new Object /* flash.text.TextField */()).x = arg1;
            loc1.y = arg2;
            loc1.width = arg3;
            loc1.height = arg4;
            loc1.text = arg5;
            loc1.selectable = false;
            loc1.setTextFormat(arg6);
            addChild(loc1);
            return loc1;
        }

        /* internal  */getRunBusinessNpc(arg1: int, arg2: int, arg3: int, arg4: Object /* flash.text.TextFormat */): void
        {
            var loc3=null;
            var loc4=null;
            var loc5=null;
            var loc1=arg2;
            var loc2=Cache.instance.scene.getRunBussinessByCamp(arg1);
            var loc6=0;
            while (loc6 < loc2.length) 
            {
                loc4 = loc2[loc6] as TaskTargetInfo;
                (loc3 = this.createTextfield(arg2, arg3, 60, 20, "", arg4)).htmlText = "<a href=\'event: 0\'><u>" + loc4.name.replace(Language.getString(35319), "") + "</u><a>";
                loc3.setTextFormat(arg4);
                loc3.addEventListener(flash.events.TextEvent.LINK, this.onNpcTxtLinkHandler);
                this._npcInfoDic[loc3.htmlText] = loc4;
                if (arg1 == ECamp._ECampNeutral || arg1 == this._selfCamp) 
                {
                    (loc5 = new FlyFootBmp()).x = loc3.x + loc3.textWidth;
                    loc5.y = loc3.y;
                    addChild(loc5);
                    loc5.addEventListener(flash.events.MouseEvent.CLICK, this.onFlyFootClickHandler);
                    this._flyFootArr.push(loc5);
                    this._targetInfoArr.push(loc4);
                }
                arg2 = arg2 + 60;
                ++loc6;
            }
            this.createTextfield(loc1 - 50, arg3, 50, 20, loc4.mapName + "：", GlobalStyle.textFormat2);
            return;
        }

        /* internal  */onNpcTxtLinkHandler(arg1: Object /* flash.events.TextEvent */): void
        {
            var loc1=arg1.target as Object /* flash.text.TextField */;
            AIManager.onAutoPathAIControl(this._npcInfoDic[loc1.htmlText]);
            return;
        }

        /* internal  */onIntroBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.RunBusinessIntroOpenOrClose));
            return;
        }

        /* internal  */onFlyFootClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=arg1.target as FlyFootBmp;
            var loc2=this._flyFootArr.indexOf(loc1);
            var loc3=this._targetInfoArr[loc2];
            AIManager.onAIControl(loc3, AIType.AI_Convey);
            return;
        }

        /* internal */ /* var */_tfBlue: Object /* flash.text.TextFormat */;

        /* internal */ /* var */_npcInfoDic: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_introBtn: GButton;

        /* internal */ /* var */_mapNameArr: Array<any>;

        /* internal */ /* var */_selfCamp: int;

        /* internal */ /* var */_flyFootArr: Array<any>;

        /* internal */ /* var */_targetInfoArr: Array<any>;

        /* internal */ /* var */_traderImg: Object /* flash.display.Bitmap */;
    }
